# -*- coding: utf-8 -*-

from osv import fields, osv

class organizacion(osv.osv):
    """
    organizacion
    """
        


        
    '''
    Campos de la clase
    '''
    _name = 'organizacion'
    _columns = {
        'name': fields.char('Nombre', size=63, required=True, help='Nombre de la organizacion'), # Nombre de la org
        'user_ids': fields.one2many('res.users','organization_id','Usuarios'),
        'incidencia_ids': fields.one2many('incidencia','organization_id','Incidencias'),
        'instalacion_ids': fields.one2many('instalacion','organization_id','Instalaciones'),
        'responsible_id': fields.many2one('res.users', 'Responsable', required=True),
       
        'create_uid': fields.many2one('res.users', 'Creado por', select=True, readonly=True), # Registro
        'create_date': fields.datetime("Fecha de creación", select=True, readonly=True),
        'write_uid': fields.many2one('res.users', 'Modificado por', select=True, readonly=True),
        'write_date': fields.datetime("Fecha de modificación", select=True, readonly=True),

    }
    
    def create(self, cr, uid, vals, context=None):
        create = super(organizacion,self).create(cr, uid, vals, context)
        users = self.pool.get("res.users")
        user_id = users.search(cr,uid,[('id','=',vals['responsible_id'])])
        users.write(cr,uid,user_id,{'organization_id':create},context)
        return create
    
    def write(self, cr, uid, ids, vals, context=None):
        write = super(organizacion,self).write(cr, uid, ids, vals, context=None)
        users = self.pool.get("res.users")
        user_id = users.search(cr,uid,[('id','=',vals['responsible_id'])])
        users.write(cr,uid,user_id,{'organization_id':write},context)
        return write
        
organizacion()


